<template>
	<view class="container">
	    <view class="example">
	      <uni-forms ref="form" :model="phouseAddForm" :rules="rules" labelWidth="80px">
			<uni-forms-item label="猪舍编码" name="phouseCode" required>
			  <uni-easyinput v-model="phouseAddForm.phouseCode" placeholder="请输入猪舍编码" />
			</uni-forms-item>
	        <uni-forms-item label="猪舍类型" name="phouseType" required>
	          <uni-data-select v-model="phouseAddForm.phouseType" placeholder="请选择猪舍类型"
	          	:localdata="hmy_park_type"
	            ></uni-data-select>
	        </uni-forms-item>
			<uni-forms-item label="负责人" name="phouseManager" required>
				<uni-data-select v-model="phouseAddForm.phouseManager" placeholder="请选择负责人"
					:localdata="staffNameList"></uni-data-select>
			</uni-forms-item>
	        <uni-forms-item label="猪舍大小" name="phouseSize" required>
	          <uni-easyinput v-model="phouseAddForm.phouseSize" placeholder="请输入猪舍大小" />
	        </uni-forms-item>
			<uni-forms-item label="猪舍备注">
				<uni-easyinput type="textarea" v-model="phouseAddForm.remark" placeholder="请输入猪舍备注" />
			</uni-forms-item>
	      </uni-forms>
		 <!-- <uni-forms-item label="温度传感器" name="phouseThermostatic" required>
		    <uni-data-select v-model="phouseAddForm.phouseThermostatic" placeholder="请选择温度传感器"
		    	:localdata="hmy_presence_absence"
		      ></uni-data-select>
		  </uni-forms-item>
		  <uni-forms-item label="湿度传感器" name="phouseWetness" required>
		    <uni-data-select v-model="phouseAddForm.phouseWetness" placeholder="请选择湿度传感器"
		    	:localdata="hmy_presence_absence"
		      ></uni-data-select>
		  </uni-forms-item>
		  <uni-forms-item label="猪舍风扇" name="phouseFans" required>
		    <uni-data-select v-model="phouseAddForm.phouseFans" placeholder="请选择猪舍风扇"
		    	:localdata="hmy_presence_absence"
		      ></uni-data-select>
		  </uni-forms-item>
		  <uni-forms-item label="猪舍监控" name="phouseMonitor" required>
		    <uni-data-select v-model="phouseAddForm.phouseMonitor" placeholder="请选择猪舍监控"
		    	:localdata="hmy_presence_absence"
		      ></uni-data-select>
		  </uni-forms-item> -->
	      <button type="primary" plain="true" @click="submit('form')">提交</button>
	    </view>
	</view>
</template>

<script>
import {addPhouse, delPhousr, findCode, getPhouse, listPhouse, updatePhousr} from "@/api/hmy/phouse";
import {listStaff, istStaffName, listStaffName} from "@/api/hmy/staff";
	export default {
		data() {
			return {
				showStatus:true,
				phouseId: '',
				phouseCode: '',
				phouse: {},
				phouseAddForm:{},
				phouseType: '',
				hmy_park_type: [{
					value: 1,
					text: '公猪舍'
				},{
					value: 2,
					text: '母猪舍'
				},{
					value: 3,
					text: '肉猪舍'
				}],
				//一个列表（id+name）
				staffNameList:[],
				// 表单校验
			  rules: {
				phouseCode: {
				  	rules: [{required: true, errorMessage: '猪舍编码不能为空'}]
				},
				phouseManager: {
				  	rules: [{required: true, errorMessage: '负责人不能为空'}]
				},
				phouseType: {
				  	rules: [{required: true, errorMessage: '猪舍类型不能为空'}]
				}
			  }
			}
		},
		created() {
			listStaffName().then(response => {
				var staffAllList = response.data;
				staffAllList.forEach(item => {
					if (item.staffType == '1') {
						this.staffNameList.push({
							'text': item.staffName,
							'value': item.staffId
						})
					}
				})
			})
		},
		methods: {
			submit(form) {
			  this.$refs[form].validate().then(res => {
				addPhouse(this.phouseAddForm).then(response => {
				  this.$modal.msgSuccess("新增成功")
				  setTimeout(()=>{
					this.$tab.navigateTo('/pages/hmy/phouse/index');
				  },1000)
				  
				})
			  })
			},
		}
	}
</script>

<style lang="scss">
	
  /* #ifndef APP-NVUE */
  page {
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    min-height: 100%;
    height: auto;
  }

  view {
    font-size: 16px;
    line-height: inherit;
  }
  /* #endif */
  .code{
	margin-bottom :5px;
  }
  .icon{
	float:right;
	margin-right:10px;
	margin-top :5px;
  }
  .message{
	margin-top:5px;
	color: #989897;
	line-height: 25px;
  }

  
  .example {
    padding: 15px;
    background-color: #fff;
  }
  
  .segmented-control {
    margin-bottom: 15px;
  }
  
  .button-group {
    margin-top: 15px;
    display: flex;
    justify-content: space-around;
  }
  
  .form-item {
    display: flex;
    align-items: center;
    flex: 1;
  }
  
  .button {
    display: flex;
    align-items: center;
    height: 35px;
    line-height: 35px;
    margin-left: 10px;
  }
</style>

